//
//  CompanySecondInfoViewController.m
//  Btpin
//
//  Created by Vic on 2019/4/1.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "CompanySecondInfoViewController.h"
#import "CompanyCreatInfoCell.h"
#import <Photos/Photos.h>
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
#import "MineInfoEditViewController.h"
#import "SelcetCityViewController.h"
#import "MineInfoEditViewController.h"
#import "PMineResumeSelfDescriptionViewController.h"
#import "CompanyJobtagViewController.h"
#import "AppDelegate.h"
#import "IDSelectViewController.h"
#import "PersonalWorkExperienceViewController.h"
#import "CompanyFirstInfoViewController.h"
#import "PersonalFirstInfoViewController.h"
#import "PersonalEducationInfoViewController.h"
#import "CompanyInfoViewController.h"

@interface CompanySecondInfoViewController ()<UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, PSSingleRowViewDelegate, SelcetCityViewControllerDelegate, MineInfoEditViewControllerDelegate, PMineResumeSelfDescriptionViewControllerDelegate, CompanyJobtagViewControllerDelegate>
{
    NSMutableArray *dataArray;
    
    PSSingleRowView *headerPickerView;
    UITableView *infoTableView;
    UIView *headerView1;
    UIView *headerView2;
    
    NSString *path;
    UIImageView *logoImgView;
    NSArray *JobtagInfoArray;
    
    NSMutableArray *modelTags;
}
@property (nonatomic, strong) PSSingleRowView *naturePickerView;
@property (nonatomic, strong) PSSingleRowView *financePickerView;
@property (nonatomic, strong) PSSingleRowView *tradePickerView;
@property (nonatomic, strong) PSSingleRowView *scalePickerView;
@end

@implementation CompanySecondInfoViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
//    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.navigationBarHidden = NO;
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if (headerPickerView) {
        headerPickerView.hidden = YES;
    }
    if (self.naturePickerView) {
        self.naturePickerView.hidden = YES;
    }
    if (self.financePickerView) {
        self.financePickerView.hidden = YES;
    }
    if (self.tradePickerView) {
        self.tradePickerView.hidden = YES;
    }
    if (self.scalePickerView) {
        self.scalePickerView.hidden = YES;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"完善企业真实信息";
    path = @"";
    modelTags = [NSMutableArray arrayWithCapacity:0];
    
    [self loadDataInfo];
    [self loadDataLocation];
    [self initUI];
}
- (void)okBtnTap {
    if (path && path.length) {
    } else {
        SVPHUDError(CompanyLogoAlertText);
        return;
    }
    if (JobtagInfoArray.count) {
    } else {
        SVPHUDError(@"请选择公司福利");
        return;
    }
    for (NSInteger i = 0; i < [dataArray[0] count]; i++) {
        PublicCategoryElementModel *model = dataArray[0][i];
        if (model.detail && model.detail.length) {
        } else {
            switch (i) {
                case 0: {
                    SVPHUDError(CompanyAlertText);
                } break;
                case 1: {
                    SVPHUDError(CompanyNameForShortAlertText);
                } break;
                case 2: {
                    SVPHUDError(CompanyTypeAlertText);
                } break;
                case 3: {
                    SVPHUDError(CompanyFinanceAlertText);
                } break;
                case 4: {
                    SVPHUDError(CompanySelectAddressAlertText);
                } break;
                case 5: {
                    SVPHUDError(CompanyTradeAlertText);
                } break;
                case 6: {
                    SVPHUDError(CompanyScaleAlertText);
                } break;
                case 7: {
                    SVPHUDError(CompanyIntroduceAlertText);
                } break;
                case 8: {
                    SVPHUDError(CompanyJobtagAlertText);
                } break;
                default:
                    break;
            }
            return;
        }
    }
    for (NSInteger i = 0; i < [dataArray[1] count]; i++) {
        PublicCategoryElementModel *model = dataArray[1][i];
        if (model.detail && model.detail.length) {
        } else {
            switch (i) {
                case 0: {
                    SVPHUDError(CompanyLandlineAlertText);
                    return;
                } break;
                case 1: {
                    SVPHUDError(CompanyAddressAlertText);
                    return;
                } break;
                default:
                    break;
            }
        }
    }
    [self updateInfo];
}
- (void)updateInfo {
    SVPHUDShow;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    dic = [UIToolsControl getPublicParameter];
    [dic setObject:path forKey:@"logo"];
    PublicCategoryElementModel *model10 = dataArray[0][0];
    [dic setObject:model10.detail forKey:@"full_name"];
    PublicCategoryElementModel *model11 = dataArray[0][1];
    [dic setObject:model11.detail forKey:@"short_name"];
    PublicCategoryElementModel *model12 = dataArray[0][2];
    [dic setObject:model12.id forKey:@"nature"];
    PublicCategoryElementModel *model13 = dataArray[0][3];
    [dic setObject:model13.id forKey:@"finance"];
    PublicCategoryElementModel *model14 = dataArray[0][4];
    [dic setObject:model14.id forKey:@"district"];
    PublicCategoryElementModel *model15 = dataArray[0][5];
    [dic setObject:model15.id forKey:@"trade"];
    PublicCategoryElementModel *model16 = dataArray[0][6];
    [dic setObject:model16.id forKey:@"scale"];
    PublicCategoryElementModel *model17 = dataArray[0][7];
    [dic setObject:model17.detail forKey:@"contents"];
    [dic setObject:JobtagInfoArray forKey:@"tags"];
    PublicCategoryElementModel *model20 = dataArray[1][0];
    [dic setObject:model20.detail forKey:@"landline_tel"];
    PublicCategoryElementModel *model21 = dataArray[1][1];
    [dic setObject:model21.detail forKey:@"address"];
    PublicCategoryElementModel *model22 = dataArray[1][2];
    [dic setObject:((model22.detail && model22.detail.length)?model22.detail:@"") forKey:@"website"];
    PublicCategoryElementModel *model23 = dataArray[1][3];
    [dic setObject:((model23.detail && model23.detail.length)?model23.detail:@"") forKey:@"email"];
    [dic setObject:@"" forKey:@"map_x"];
    [dic setObject:@"" forKey:@"map_y"];
    [dic setObject:@"" forKey:@"map_zoom"];
    
    [BaseNetManager requestWithMethod:POST path:Company_SaveBaseInfo_URL params:dic successBlock:^(NSDictionary * _Nonnull responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            SVPHUDSuccess(responseObject[@"msg"]);
            
            [DataToolsControl getMyBaseInfoForCompany:^(BOOL requestFlag) {
                [SharedApp showViewController:TabBarTypeOfCompany];
                UITabBarController *tabBarController = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
                tabBarController.selectedIndex = tabBarController.viewControllers.count-1;
            }];
        } else {
            SVPHUDError(responseObject[@"msg"]);
        }
    } failurBlock:^(NSError * _Nonnull error) {
        SVPHUDError(NetErrorAlertText);
    }];
}
- (void)loadDataInfo {
    self.naturePickerView = [[PSSingleRowView alloc] initWithData:[DataToolsControl sharedManager].allCategoryInfoModel.companyTypeArray target:self];
    self.naturePickerView.hidden = YES;
    self.financePickerView = [[PSSingleRowView alloc] initWithData:[DataToolsControl sharedManager].allCategoryInfoModel.financeArray target:self];
    self.financePickerView.hidden = YES;
    self.tradePickerView = [[PSSingleRowView alloc] initWithData:[DataToolsControl sharedManager].allCategoryInfoModel.tradeArray target:self];
    self.tradePickerView.hidden = YES;
    self.scalePickerView = [[PSSingleRowView alloc] initWithData:[DataToolsControl sharedManager].allCategoryInfoModel.scaleArray target:self];
    self.scalePickerView.hidden = YES;
}
- (void)initUI {
    if (self.isRegisterPush) {
//        [self.navigationController popViewControllerAnimated:YES];
    } else {
        UIButton *switchBtn = [UIToolsControl initButtonWithFrame:CGRectMake(0, 0, 60*Scale, 44) imageName:nil target:self action:@selector(switchBtnTap) title:@"  我要求职" titleColor:THEMECOLOR_OF_ORANGE];
        switchBtn.titleLabel.font = Font(Font_15);
        UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:switchBtn];
        self.navigationItem.leftBarButtonItem = leftItem;
    }
    
    UIButton *okBtn = [UIToolsControl initButtonWithFrame:CGRectMake(WIDTH-50*Scale, HeightOfStatusBar+3*Scale, 50*Scale, 36) imageName:nil target:self action:@selector(okBtnTap) title:@"提交" titleColor:THEMECOLOR_OF_ORANGE];
    okBtn.titleLabel.font = Font(Font_15);
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:okBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    headerView1 = [UIToolsControl initViewWithFrame:CGRectMake(0, 0, WIDTH, 130*Scale) backgroundColor:COLOR_OF_WHITE];
    UILabel *leftLbl = [UIToolsControl initLabelWithFrame:CGRectMake(LeftSpace, 0, WIDTH-30*Scale, 120*Scale) text:@"LOGO是企业文化的彰显，\n\n\n可提升企业的信用度" textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    leftLbl.numberOfLines = 0;
    leftLbl.lineBreakMode = NSLineBreakByWordWrapping;
    [headerView1 addSubview:leftLbl];
    logoImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(WIDTH-100*Scale, 15*Scale, 70*Scale, 70*Scale) imageName:@"logo_bg"];
    [headerView1 addSubview:logoImgView];
    UILabel *rightLbl = [UIToolsControl initLabelWithFrame:CGRectMake(WIDTH-100*Scale, EndY(logoImgView), 100*Scale, 30*Scale) text:@"上传企业LOGO" textColor:THEMECOLOR_OF_ORANGE font:Font_10];
    [headerView1 addSubview:rightLbl];
    UIView *view = [UIToolsControl initViewWithFrame:CGRectMake(0, 120*Scale, WIDTH, 10*Scale) backgroundColor:THEMECOLOR_OF_GRAY];
    [headerView1 addSubview:view];
    UIButton *headerBtn = [UIToolsControl initButtonWithFrame:CGRectMake(0, 0, WIDTH, 130*Scale) imageName:nil target:self action:@selector(headerBtnTap) title:nil titleColor:nil];
    [headerView1 addSubview:headerBtn];
    
    headerView2 = [UIToolsControl initViewWithFrame:CGRectMake(0, 0, WIDTH, 10*Scale) backgroundColor:THEMECOLOR_OF_GRAY];
    
    
    infoTableView = [UIToolsControl initTableViewWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-HeightOfStatusBarAndNavigationBar-SIMEmojKeyBoardkBottomNOSafeArea_Height) target:self style:UITableViewStyleGrouped];
    infoTableView.rowHeight = 45*Scale;
    infoTableView.tableFooterView = [[UIView alloc] init];
    infoTableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    [self.view addSubview:infoTableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [dataArray[section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CompanyCreatInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:isCellID];
    if (!cell) {
        cell = [[CompanyCreatInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:isCellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (indexPath.row) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
    PublicCategoryElementModel *model = dataArray[indexPath.section][indexPath.row];
    [cell reloadDataModel:model];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section) {
        switch (indexPath.row) {
            case 0: { // 企业座机
                [self pushInfoEditVC:InfoEditTypeOfCompanyLandline];
            } break;
            case 1: { // 办公地址
                [self pushInfoEditVC:InfoEditTypeOfCompanyAddress];
            } break;
            case 2: { // 企业网站
                [self pushInfoEditVC:InfoEditTypeOfCompanyWebURL];
            } break;
            case 3: { // 企业邮箱
                [self pushInfoEditVC:InfoEditTypeOfEmail];
            } break;
            default:
                break;
        }
    } else {
        switch (indexPath.row) {
            case 0: { // 企业名称
                PublicCategoryElementModel *model = dataArray[0][0];
                if (model.detail && model.detail.length) {
                } else {
                    [self pushInfoEditVC:InfoEditTypeOfCompanyName];
                }
            } break;
            case 1: { // 企业简称
                [self pushInfoEditVC:InfoEditTypeOfCompanyNameForShort];
            } break;
            case 2: { // 企业性质
                self.naturePickerView.hidden = NO;
            } break;
            case 3: { // 融资阶段
                self.financePickerView.hidden = NO;
            } break;
            case 4: { // 所在地区
                SelcetCityViewController *SCVC = [[SelcetCityViewController alloc] init];
                SCVC.delegate = self;
                [self.navigationController pushViewController:SCVC animated:YES];
            } break;
            case 5: { // 所属行业
                self.tradePickerView.hidden = NO;
            } break;
            case 6: { // 企业规模
                self.scalePickerView.hidden = NO;
            } break;
            case 7: { // 企业介绍
                PublicCategoryElementModel *model = dataArray[0][7];
                PMineResumeSelfDescriptionViewController *PMRSDVC = [[PMineResumeSelfDescriptionViewController alloc] init];
                if (model.detail && model.detail.length) {
                    PMRSDVC.context = model.detail;
                }
                PMRSDVC.limitTextMaxNumber = 1000;
                PMRSDVC.titleStr = @"企业介绍";
                PMRSDVC.delegate = self;
                [self.navigationController pushViewController:PMRSDVC animated:YES];
            } break;
            case 8: { // 企业福利
                CompanyJobtagViewController *CJVC = [[CompanyJobtagViewController alloc] init];
                CJVC.tagArr = [NSMutableArray arrayWithCapacity:0];
                if (modelTags && modelTags.count) {
                    for (TagModel *mmodel in modelTags) {
                        [CJVC.tagArr addObject:[mmodel copy]];
                    }
                }
                CJVC.delegate = self;
                [self.navigationController pushViewController:CJVC animated:YES];
            } break;
            default:
                break;
        }
    }
}
- (void)companyJobtagViewControllerBackInfo:(NSString *)infoStr infoArray:(NSArray *)infoArray modelArray:(nonnull NSArray *)modelArray {
    if (modelArray && modelArray.count) {
        [modelTags removeAllObjects];
        for (TagModel *mmodel in modelArray) {
            [modelTags addObject:[mmodel copy]];
        }
    }
    JobtagInfoArray = infoArray;
    PublicCategoryElementModel *tempModel = dataArray[0][8];
    tempModel.detail = infoStr;
    [dataArray[0] replaceObjectAtIndex:8 withObject:tempModel];
    [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:8 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
}
- (void)pMineResumeSelfDescriptionViewControllerBack:(NSString *)info {
    PublicCategoryElementModel *tempModel = dataArray[0][7];
    tempModel.detail = info;
    [dataArray[0] replaceObjectAtIndex:7 withObject:tempModel];
    [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:7 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
}
- (void)pushInfoEditVC:(InfoEditType)type {
    MineInfoEditViewController *MIEVC = [[MineInfoEditViewController alloc] init];
    MIEVC.text = @"";
    switch (type) {
        case InfoEditTypeOfCompanyNameForShort: {
            PublicCategoryElementModel *model = dataArray[0][1];
            MIEVC.text = model.detail;
        } break;
        case InfoEditTypeOfCompanyLandline: {
            PublicCategoryElementModel *model = dataArray[1][0];
            MIEVC.text = model.detail;
        } break;
        case InfoEditTypeOfCompanyAddress: {
            PublicCategoryElementModel *model = dataArray[1][1];
            MIEVC.text = model.detail;
        } break;
        case InfoEditTypeOfCompanyWebURL: {
            PublicCategoryElementModel *model = dataArray[1][2];
            MIEVC.text = model.detail;
        } break;
        case InfoEditTypeOfEmail: {
            PublicCategoryElementModel *model = dataArray[1][3];
            MIEVC.text = model.detail;
        } break;
        default:
            break;
    }
    MIEVC.type = type;
    MIEVC.delegate = self;
    [self.navigationController pushViewController:MIEVC animated:YES];
}
- (void)mineInfoEditViewController:(NSString *)info type:(InfoEditType)type {
    switch (type) {
        case InfoEditTypeOfCompanyName: {
            PublicCategoryElementModel *tempModel = dataArray[0][0];
            tempModel.detail = info;
            [dataArray[0] replaceObjectAtIndex:0 withObject:tempModel];
            [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
        } break;
        case InfoEditTypeOfCompanyNameForShort: {
            PublicCategoryElementModel *tempModel = dataArray[0][1];
            tempModel.detail = info;
            [dataArray[0] replaceObjectAtIndex:1 withObject:tempModel];
            [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:1 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
        } break;
        case InfoEditTypeOfCompanyLandline: {
            PublicCategoryElementModel *tempModel = dataArray[1][0];
            tempModel.detail = info;
            [dataArray[1] replaceObjectAtIndex:0 withObject:tempModel];
            [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:1], nil] withRowAnimation:UITableViewRowAnimationNone];
        } break;
        case InfoEditTypeOfCompanyAddress: {
            PublicCategoryElementModel *tempModel = dataArray[1][1];
            tempModel.detail = info;
            [dataArray[1] replaceObjectAtIndex:1 withObject:tempModel];
            [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:1 inSection:1], nil] withRowAnimation:UITableViewRowAnimationNone];
        } break;
        case InfoEditTypeOfCompanyWebURL: {
            PublicCategoryElementModel *tempModel = dataArray[1][2];
            tempModel.detail = info;
            [dataArray[1] replaceObjectAtIndex:2 withObject:tempModel];
            [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:2 inSection:1], nil] withRowAnimation:UITableViewRowAnimationNone];
        } break;
        case InfoEditTypeOfEmail: {
            PublicCategoryElementModel *tempModel = dataArray[1][3];
            tempModel.detail = info;
            [dataArray[1] replaceObjectAtIndex:3 withObject:tempModel];
            [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:3 inSection:1], nil] withRowAnimation:UITableViewRowAnimationNone];
        } break;
        default:
            break;
    }
}
- (void)selcetCityViewControllerInfo:(NSDictionary *)dic {
    PublicCategoryElementModel *tempModel = dataArray[0][4];
//    tempModel.detail = [NSString stringWithFormat:@"%@-%@-%@", dic[@"province"], dic[@"city"], dic[@"area"]];
//    tempModel.id = [NSString stringWithFormat:@"%@.%@.%@", dic[@"provinceid"], dic[@"cityid"], dic[@"areaid"]];
    
    if ([[NSString stringWithFormat:@"%@", dic[@"cityid"]] integerValue] == 0) {
        tempModel.id = [NSString stringWithFormat:@"%@", dic[@"provinceid"]];
        tempModel.detail = dic[@"province"];
    } else {
        tempModel.id = [NSString stringWithFormat:@"%@.%@", dic[@"provinceid"], dic[@"cityid"]];
        tempModel.detail = [NSString stringWithFormat:@"%@-%@", dic[@"province"], dic[@"city"]];
    }
    
    [dataArray[0] replaceObjectAtIndex:4 withObject:tempModel];
    [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:4 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section) {
        return headerView2;
    } else {
        return headerView1;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section) {
        return 10*Scale;
    }
    return 130*Scale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.00001;
}

- (void)psSingleRowViewCancel:(PSSingleRowView *)psSingleRowView {
    psSingleRowView.hidden = YES;
}
- (void)psSingleRowViewOk:(PublicCategoryElementModel *)model PSSingleRowView:(PSSingleRowView *)psSingleRowView {
    psSingleRowView.hidden = YES;
    if (psSingleRowView == self.naturePickerView) {
        PublicCategoryElementModel *tempModel = dataArray[0][2];
        tempModel.detail = model.name;
        tempModel.id = model.id;
        [dataArray[0] replaceObjectAtIndex:2 withObject:tempModel];
        [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:2 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
    } else if (psSingleRowView == self.financePickerView) {
        PublicCategoryElementModel *tempModel = dataArray[0][3];
        tempModel.detail = model.name;
        tempModel.id = model.id;
        [dataArray[0] replaceObjectAtIndex:3 withObject:tempModel];
        [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:3 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
    } else if (psSingleRowView == self.tradePickerView) {
        PublicCategoryElementModel *tempModel = dataArray[0][5];
        tempModel.detail = model.name;
        tempModel.id = model.id;
        [dataArray[0] replaceObjectAtIndex:5 withObject:tempModel];
        [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:5 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
    } else if (psSingleRowView == self.scalePickerView) {
        PublicCategoryElementModel *tempModel = dataArray[0][6];
        tempModel.detail = model.name;
        tempModel.id = model.id;
        [dataArray[0] replaceObjectAtIndex:6 withObject:tempModel];
        [infoTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:6 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
    } else if (psSingleRowView == headerPickerView) {
        if ([model.id integerValue] == 1) { // 相册
            [self openPhotoLibrary];
        } else { // 拍摄
            [self openCamera];
        }
    }
}
- (void)loadDataLocation {
    NSMutableArray *headerArray = [NSMutableArray arrayWithCapacity:0];
    PublicCategoryElementModel *model111 = [[PublicCategoryElementModel alloc] init];
    [model111 setValuesForKeysWithDictionary:@{@"id":@"0", @"name":@"拍摄"}];
    [headerArray addObject:model111];
    PublicCategoryElementModel *model222 = [[PublicCategoryElementModel alloc] init];
    [model222 setValuesForKeysWithDictionary:@{@"id":@"1", @"name":@"相册"}];
    [headerArray addObject:model222];
    headerPickerView = [[PSSingleRowView alloc] initWithData:headerArray target:self];
    headerPickerView.hidden = YES;
    
    if (([DataToolsControl sharedManager].companyBaseInfoModel && [DataToolsControl sharedManager].companyBaseInfoModel.tag.count)) {
        for (TagModel *model in [DataToolsControl sharedManager].companyBaseInfoModel.tag) {
            [modelTags addObject:[model copy]];
        }
    }
    
    dataArray = [NSMutableArray arrayWithCapacity:0];
    NSMutableArray *arr1 = [NSMutableArray arrayWithCapacity:0];
    PublicCategoryElementModel *model1 = [[PublicCategoryElementModel alloc] init];
    model1.name = @"企业名称";
    if (self.companyName && self.companyName.length) {
        model1.detail = self.companyName;
    } else if ([DataToolsControl sharedManager].companyBaseInfoModel && [DataToolsControl sharedManager].companyBaseInfoModel.full_name.length) {
        model1.detail = [DataToolsControl sharedManager].companyBaseInfoModel.full_name;
    } else if (UD_GetOForK(isCompanyName) && [UD_GetOForK(isCompanyName) length]) {
           model1.detail = UD_GetOForK(isCompanyName);
    }
    [arr1 addObject:model1];
    PublicCategoryElementModel *model2 = [[PublicCategoryElementModel alloc] init];
    model2.name = @"企业简称";
    [arr1 addObject:model2];
    PublicCategoryElementModel *model3 = [[PublicCategoryElementModel alloc] init];
    model3.name = @"企业性质";
    [arr1 addObject:model3];
    PublicCategoryElementModel *model4 = [[PublicCategoryElementModel alloc] init];
    model4.name = @"融资阶段";
    [arr1 addObject:model4];
    PublicCategoryElementModel *model5 = [[PublicCategoryElementModel alloc] init];
    model5.name = @"所在地区";
    [arr1 addObject:model5];
    PublicCategoryElementModel *model6 = [[PublicCategoryElementModel alloc] init];
    model6.name = @"所属行业";
    [arr1 addObject:model6];
    PublicCategoryElementModel *model7 = [[PublicCategoryElementModel alloc] init];
    model7.name = @"企业规模";
    [arr1 addObject:model7];
    PublicCategoryElementModel *model8 = [[PublicCategoryElementModel alloc] init];
    model8.name = @"企业介绍";
    [arr1 addObject:model8];
    PublicCategoryElementModel *model9 = [[PublicCategoryElementModel alloc] init];
    model9.name = @"企业福利";
    [arr1 addObject:model9];
    [dataArray addObject:arr1];
    
    NSMutableArray *arr2 = [NSMutableArray arrayWithCapacity:0];
    PublicCategoryElementModel *model21 = [[PublicCategoryElementModel alloc] init];
    model21.name = @"企业座机";
    [arr2 addObject:model21];
    PublicCategoryElementModel *model22 = [[PublicCategoryElementModel alloc] init];
    model22.name = @"办公地址";
    [arr2 addObject:model22];
    PublicCategoryElementModel *model23 = [[PublicCategoryElementModel alloc] init];
    model23.name = @"企业网址";
    [arr2 addObject:model23];
    PublicCategoryElementModel *model24 = [[PublicCategoryElementModel alloc] init];
    model24.name = @"企业邮箱";
    [arr2 addObject:model24];
    [dataArray addObject:arr2];
}
- (void)headerBtnTap {
    headerPickerView.hidden = NO;
}
- (void)openCamera {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    
    AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (status == AVAuthorizationStatusRestricted || status == AVAuthorizationStatusDenied) { // 无权限
        CustomView *alertView = [[CustomView alloc] initWithTitle:@"相机权限未开启" message:@"相机权限未开启，请进入系统【设置】>【隐私】>【相机】中打开开关,开启相机功能" prompt:nil sureBtn:@"确定" cancleBtn:@"取消" size:170];
        alertView.resultIndex = ^(NSInteger index) { //回调---处理一系列动作
            if (index == 2) {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
            }
        };
        [alertView showXLAlertView];
    } else { // 有权限
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:picker animated:YES completion:nil];
    }
}
- (void)openPhotoLibrary {
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
    if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied) { // 无权限
        CustomView *alertView = [[CustomView alloc] initWithTitle:@"相册权限未开启" message:@"相册权限未开启，请进入系统【设置】>【隐私】>【相册】中打开开关,开启相册功能" prompt:nil sureBtn:@"确定" cancleBtn:@"取消" size:170];
        alertView.resultIndex = ^(NSInteger index) { //回调---处理一系列动作
            if (index == 2) {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
            }
        };
        [alertView showXLAlertView];
    } else { // 有权限
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.delegate = self;
        imagePicker.navigationBar.translucent = NO;
        imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:imagePicker animated:YES completion:^{
            NSLog(@"打开相册");
        }];
    }
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    NSLog(@"finish..");
    UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
    SVPHUDShow;
    [DataToolsControl uploadImgType:UploadImgTypeOfCompanyLogo image:image successBlock:^(NSDictionary *responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            id data = responseObject[@"data"];
            self->path = data[@"url"];
            self->logoImgView.image = image;
            SVPHUDDismiss;
        } else {
            SVPHUDError(responseObject[@"msg"]);
        }
    } failurBlock:^(NSError *error) {
        SVPHUDError(@"上传失败，请重新操作");
    }];
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)switchBtnTap {
    NSLog(@"切换角色");
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    dic = [UIToolsControl getPublicParameter];
    [dic setObject:@"2" forKey:@"user_role"];
    [BaseNetManager requestWithMethod:POST path:Change_Role_URL params:dic successBlock:^(NSDictionary *responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            UD_SetOForK(@"2", isUserRole);
            
            NSDictionary *data = responseObject[@"data"];
            if (data[@"user_guide"] && [data[@"user_guide"] length] && ([data[@"user_guide"] isEqualToString:@"choose_role"])) { // 用户还没选角色 （选择用户角色）
                IDSelectViewController *IDSVC = [[IDSelectViewController alloc] init];
                IDSVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:IDSVC animated:NO];
            } else {
                if ([data[@"user_guide"] isEqualToString:@"company_add_job"]) { // 添加工作
                    [DataToolsControl getMyBaseInfoForCompany:^(BOOL requestFlag) {
                        [SharedApp showViewController:TabBarTypeOfCompany];
                        UITabBarController *tabBarController = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
                        tabBarController.selectedIndex = 1;
                    }];
                } else if ([data[@"user_guide"] isEqualToString:@"company_create"]) { // 招聘者下面没有企业的话就会引导创建
                    CompanyFirstInfoViewController *IDSVC = [[CompanyFirstInfoViewController alloc] init];
                    IDSVC.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:IDSVC animated:NO];
                } else if ([data[@"user_guide"] isEqualToString:@"company_info"]) { // 填写企业信息
                    CompanySecondInfoViewController *IDSVC = [[CompanySecondInfoViewController alloc] init];
                    IDSVC.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:IDSVC animated:NO];
                } else if ([data[@"user_guide"] isEqualToString:@"company_audit"]) { // 企业未认证
                    SVPHUDShow;
                    [DataToolsControl getMyBaseInfoForCompany:^(BOOL requestFlag) {
                        SVPHUDDismiss;
                        [SharedApp showViewController:TabBarTypeOfCompany];
                        UITabBarController *tabBarController = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
                        tabBarController.selectedIndex = tabBarController.viewControllers.count-1;
                        UINavigationController *navigationController = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
                        
                        CompanyInfoViewController *CIVC = [[CompanyInfoViewController alloc] init];
                        CIVC.hidesBottomBarWhenPushed = YES;
                        [navigationController pushViewController:CIVC animated:YES];
                    }];
                } else if (([data[@"user_guide"] isEqualToString:@"resume_create"])) { // 创建简历页
                    PersonalFirstInfoViewController *PMRVC = [[PersonalFirstInfoViewController alloc] init];
                    PMRVC.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:PMRVC animated:NO];
                } else if ([data[@"user_guide"] isEqualToString:@"resume_edu"]) { // 完善简历中教育经历
                    if (data[@"is_graduate"] && ([data[@"is_graduate"] integerValue] == 0)) {
                        [DataToolsControl sharedManager].idType = IDTypeOfWorker;
                    } else {
                        [DataToolsControl sharedManager].idType = IDTypeOfFreshGraduate;
                    }
                    
                    PersonalEducationInfoViewController *PMRVC = [[PersonalEducationInfoViewController alloc] init];
                    PMRVC.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:PMRVC animated:NO];
                } else if ([data[@"user_guide"] isEqualToString:@"resume_work"]) { // 完善简历中工作经历
                    PersonalWorkExperienceViewController *PMRVC = [[PersonalWorkExperienceViewController alloc] init];
                    PMRVC.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:PMRVC animated:NO];
                } else {
                    [DataToolsControl getMyBaseInfoForWorker:^(BOOL requestFlag) {
                        [SharedApp showViewController:TabBarTypeOfPersonal];
                    }]; 
                }
            }
        } else {
            SVPHUDError(responseObject[@"msg"]);
        }
    } failurBlock:^(NSError *error) {
        SVPHUDError(NetErrorAlertText);
    }];
}
- (void)customBackButtonTap {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
